package com.wxx;

import java.util.Arrays;

/**
 * @author: Jetwang
 * @date: 2022/3/19 19:31
 * @description: InsertionSort 插入排序
 * @version: 1.0
 */
public class InsertionSort {
    public static void insertionSort(Integer[] arr) {
        for (int i = 1; i < arr.length; i++) {
            for (int j = i; j > 0; j--) {
                if (arr[j-1] > arr[j]) {
                    int temp = arr[j-1];
                    arr[j-1] = arr[j];
                    arr[j] = temp;
                } else {
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {
        Integer[] arr = {2, 5, 1, 6, 3};
        insertionSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
